# -*- coding: UTF-8 -*-
class Action(object):
    def encode(self, name: str) -> int:
        return getattr(self, name) if hasattr(self, name) else None

    def decode(self, code: int) -> int:
        for _ in self.get_props():
            if getattr(self, _) == code:
                return _

    @classmethod
    def get_props(cls):
        return [x for x in dir(cls) if isinstance(getattr(cls, x), property)]

    def get_choices(self):
        # return tuple([(getattr(self, _), _) for _ in self.get_props()])
        return [(getattr(self, _), _) for _ in self.get_props()]


class UserActionProperty(Action):
    @property
    def init(self):
        """等待用户操作,用户未操作"""
        return 0

    @property
    def saved(self):
        return 1 << 0

    @property
    def passed(self):
        return 1 << 1

    @property
    def rejected(self):
        return 1 << 2

    @property
    def stoped(self):
        return 1 << 3

    @property
    def returned(self):
        return 1 << 4

    @property
    def voided(self):
        return 1 << 5





class ProcessStatusProperty(Action):
    @property
    def init(self):
        """等待用户处理,用户未处理"""
        return 0

    @property
    def processed(self):
        """已处理"""
        return 1

    @property
    def exception(self):
        """处理过程异常"""
        return 1 << 1


class TaskStatusProperty(Action):
    @property
    def init(self):
        """初始化中,待处理的"""
        return 0

    @property
    def saved(self):
        """保存"""
        return 1

    @property
    def processing(self):
        """处理中"""
        return 1 << 1

    @property
    def processed(self):
        """已处理"""
        return 1 << 2

    @property
    def completed(self):
        """任务已结束"""
        return 1 << 3

    @property
    def stoped(self):
        """任务已停止"""
        return 1 << 4

    @property
    def voided(self):
        """任务已作废"""
        return 1 << 5

    @property
    def exception(self):
        """任务异常"""
        return 1 << 6

    @property
    def timeout(self):
        """任务超时"""
        return 1 << 7

UserAction = UserActionProperty()
ProcessStatus = ProcessStatusProperty()
TaskStatus = TaskStatusProperty()
